﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using DBO.Economy;
using DBO;
using BusinessManagement;
using BusinessManagement.Economy;

namespace RESTDataService
{
    public class RESTDataService : IRESTDataService
    {
        public Resources GetResource(string name)
        {
            Logger.ConsoleLogger.Log("REST Get Resource called with : " + name);
            return ServerDataSingleton.Instance.ResourceRepository.Get<Resources>(name);
        }

        public Resources GetPlayerResource(string token)
        {
            return PlayerEconomy.GetPlayerResources(token);
        }

        public UnitStatistics GetStatistics(string name)
        {
            return ServerDataSingleton.Instance.ResourceRepository.Get<UnitStatistics>(name);
        }

        public IList<Race> GetRaces()
        {
            Console.WriteLine("Get races called.");

            RaceDictionary Dict = (RaceDictionary) ServerDataSingleton.Instance.ResourceRepository.GetDictionnary<Race>();

            return Dict.GetAll();
        }

        public bool BuySlot(string token, string type)
        {
            return PlayerEconomy.BuySlot(token, type);
        }

        public bool SellSlot(string token, string type)
        {
            return PlayerEconomy.SellSlot(token, type);
        }

        public int CountSlots(string token, string type)
        {
            return PlayerEconomy.CountSlots(token, type);
        }

        public Player GetPlayerInfo(string token)
        {
            return BusinessManagement.SessionContainer.GetPlayerInfo(token);
        }
    }
}
